package edu.winona.csclub.testing.utils;

import java.io.File;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;

import edu.winona.csclub.testing.generators.EnumProvider;

public class FileSystem {

	private static final String GENPATH = "edu/winona/csclub/testing/generators";
	
	public static HashMap<String,Class> getLocalEnumProviders(){
	    File genDir = new File(GENPATH);
	    HashMap<String,Class> ls = new HashMap<String,Class>();
	    for( File f : genDir.listFiles()){
	    	if( !f.getPath().endsWith(".class"))continue;
	    	try{
	    		String cls =  f.getPath().replace('/', '.');
	    		cls = cls.substring(0,cls.length()-6);
	    		Class c =Class.forName(cls);
	    		if(EnumProvider.class.isAssignableFrom(c)){
	    			ls.put(c.getName().substring(c.getName().lastIndexOf('.')+1), c);
	    		}
	    	}catch(Exception e){
	    		e.printStackTrace();
	    	}
	    }
	   // String possibilities[] = new String[ls.keySet().size()-1];
	    int i = 0;
	    List<String> rem = new LinkedList<String>();
	    for( String key : ls.keySet() ){
	    	if( key.equals("EnumProvider"))rem.add(key);
	    //	possibilities[i]=key;
	    	i++;
	    }
	    for( String k : rem ){
	    	ls.remove(k);
	    }
	    return ls;
	}
	

}
